import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'logger_plugin_platform_interface.dart';

/// An implementation of [LoggerPluginPlatform] that uses method channels.
class MethodChannelLoggerPlugin extends LoggerPluginPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('logger_plugin1');

  @override
  Future<String?> getPlatformVersion() async {
    final version =
        await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  void logI(String tag, String msg) {
    methodChannel
        .invokeMethod<void>('logI', <String, dynamic>{"tag": tag, "msg": msg});
  }

  @override
  Future<void> logE(String tag, String msg) {
    try {
      return methodChannel
          .invokeMethod('logI', <String, dynamic>{"tag": tag, "msg": msg});
    } on PlatformException catch (e) {
      throw ArgumentError(' logE error tag:$tag,msg:$msg,  ${e.message}');
    }
  }
}
